<template>
	<view class="layout">
		<uni-header :leftIcon="true" :title="'主观评价'"></uni-header>
		<view class="content">
			<view class="evaluate">
				<view class="evaluate-list">
					<text class="title-text">课程名称</text>
					<u-input v-model="formData.course_name" type="text" placeholder="请输入课程名称" input-align="right"
						border="false" />
				</view>
				<view class="evaluate-list">
					<text class="title-text">授课类型</text>
					<u-input v-model="formData.course_type" type="text" placeholder="请输入授课类型" input-align="right"
						border="false" />
				</view>
				<view class="evaluate-list">
					<text class="title-text">作业设计</text>
					<u-input v-model="formData.course_task" type="text" placeholder="请输入作业设计" input-align="right"
						border="false" />
				</view>
			</view>
			<view class="evaluate">
				<view class="evaluate-list">
					<text class="title-text">媒体使用</text>
					<view class="right-text"><uni-data-checkbox :localdata="is_media" v-model="formData.is_media" />
					</view>
				</view>
				<view class="evaluate-list">
					<text class="title-text">备课一致</text>
					<view class="right-text"><uni-data-checkbox :localdata="prepare" v-model="formData.prepare" />
					</view>
				</view>
			</view>
			<view class="evaluate">
				<view class="evaluate-list">
					<text class="title-text">评价</text>
				</view>
				<view class="evaluate-list">
					<uni-data-checkbox :localdata="sexs" v-model="formData.level" />
				</view>
			</view>
			<view class="evaluate">
				<view class="evaluate-list">
					<uni-easyinput type="textarea" v-model="formData.evaluate_comment" placeholder="请输入评价内容" />
				</view>
			</view>
			<view class="evaluate">
				<view class="evaluate-list">
					<text class="title-text">评价模板选择</text>
				</view>
				<view class="evaluate-list">
					<uni-data-checkbox :localdata="commentData" v-model="formData.evaluate_comment" />
				</view>
			</view>
			<u-button type="primary" @click="onSubmitClick">保存</u-button>
		</view>
	</view>
</template>

<script>
	import {
		getEstimate,
		addEstimate,
		addEmulateEvaluate,
		getEmulateEvaluate
	} from "@/api/home"
	import {
		getComment
	} from "@/api/mine"
	export default {
		data() {
			return {
				formData: {
					type: "",
					deviceId: this.$store.state.user.deviceId,
					activityId: "",
					course_name: "",
					course_type: "",
					course_task: "",
					is_media: "",
					prepare: "",
					level: "",
					evaluate_comment: "",
				},
				commentData: [],
				sexs: [{
					text: '优',
					value: 0
				}, {
					text: '良',
					value: 1
				}, {
					text: '中',
					value: 2
				}, {
					text: '差',
					value: 3
				}],
				is_media: [{
					text: '未使用',
					value: 0
				}, {
					text: '已使用',
					value: 1
				}],
				prepare: [{
					text: '是',
					value: 0
				}, {
					text: '否',
					value: 1
				}],
			}
		},
		onLoad(option) {
			this.type = option.type;
			this.formData.activityId = option.activeId;
			if (this.type == "emulate") {
				this.getEmulateEstimate();
			} else if (this.type == "class") {
				this.getClassEstimate();
			}
			getComment({
				deviceId: this.$store.state.user.deviceId
			}).then(res => {
				res.dataList.list.forEach(item => {
					this.commentData.push({
						value: item.comment,
						text: item.comment
					})
				})
			})
		},
		methods: {
			//获取听评课下评价信息
			getClassEstimate() {
				getEstimate({
					activityId: this.formData.activityId,
					deviceId: this.formData.deviceId
				}).then(res => {
					this.formData.estimate_id = res.estimate_id;
					this.formData.course_name = res.course_name;
					this.formData.course_type = res.course_type;
					this.formData.course_task = res.course_task;
					this.formData.is_media = res.is_media;
					this.formData.prepare = res.prepare;
					this.formData.level = res.level;
					this.formData.evaluate_comment = res.evaluate_comment;
				});
			},
			//获取观摩课下评价信息
			getEmulateEstimate() {
				getEmulateEvaluate({
					activityId: this.formData.activityId,
					deviceId: this.formData.deviceId
				}).then(res => {
					this.formData.estimate_id = res.estimate_id;
					this.formData.course_name = res.course_name;
					this.formData.course_type = res.course_type;
					this.formData.course_task = res.course_task;
					this.formData.is_media = res.is_media;
					this.formData.prepare = res.prepare;
					this.formData.level = res.level;
					this.formData.evaluate_comment = res.evaluate_comment;
				});
			},
			//保存评价信息
			onSubmitClick() {
				if (this.type == "class") {
					this.addClassData();
				} else if (this.type == "emulate") {
					this.addEmulateData();
				}
			},
			//保存观摩课数据
			addEmulateData() {
				addEmulateEvaluate(this.formData).then(res => {
					if (res.status == "0") {
						uni.$u.toast('保存成功');
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
							// this.$tab.reLaunch('/pages/activity/index?id='+this.formData.activityId)
						}, 2000);
					}
				})
			},
			//保存听评课数据
			addClassData() {
				addEstimate(this.formData).then(res => {
					if (res.status == "0") {
						uni.$u.toast('保存成功');
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
							// this.$tab.reLaunch('/pages/activity/index?id='+this.formData.activityId)
						}, 2000);
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.layout {
		.content {
			.evaluate {
				background: #fff;
				margin-bottom: 15px;

				.evaluate-list {
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1px solid #ddd;
					padding: 10px 15px;

					.left-title {
						width: 20vw;
					}

					.right {
						width: 80vw;
						text-align: right;
					}
				}
			}
		}
	}
</style>